/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.wiztools.xpathevaluator;

import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

/**
 *
 * @author subwiz
 */
public class Main {
    public static void main(String[] arg){
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame jf = new JFrame("WizTools.org XPath Evaluator");
                
                final MessageDialog dialog = new MessageDialog(jf);
                
                final OutputPanel oPanel = new OutputPanel();
                
                View view = new View() {
                    public void doResult(final String str) {
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                oPanel.setResult(str);
                            }
                        });
                        
                    }

                    public void doError(final Throwable ex) {
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                dialog.showMessage(Util.getStackTrace(ex));
                            }
                        });
                        
                    }
                };
                
                InputPanel iPanel = new InputPanel(view);
                
                Container c = jf.getContentPane();
                c.setLayout(new BorderLayout(Util.WIDTH, Util.WIDTH));
                JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
                jsp.setTopComponent(iPanel);
                jsp.setBottomComponent(oPanel);
                c.add(jsp, BorderLayout.CENTER);
                jf.pack();
                jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                jf.setVisible(true);
            }
        });
    }
    
}
